<template>
  <div class="Arrangementmode">
    <div class="main">
      <div class="imglist" v-for="(item,index) in hotAlbums" :key="item.id" @click="getplaylistid(item.id)">
        <img :src="item.blurPicUrl" alt="">
        <div style="display:flex;" class="p1">
          <p>{{item.name}}</p>
          <span v-for="(item2,index2) in title" :key="index2" v-show="index==index2" style="opacity: 0.6;">{{item2}}</span>
        </div>
        <p class="p2" v-for="(item1,index1) in Timemerge" :key="index1" v-show="index==index1">{{item1}}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'Arrangementmode',
  data() {
    return {
      limit: 30,
      time: [],
      UTCFullYear: [],
      Month: [],
      UTCDate: [],
      Timemerge: [],
      title: []
    }
  },
  computed: {
    ...mapState({
      hotAlbums: state => state.Singger.hotAlbums
    })
  },
  methods: {
    getplaylistid(e) {
      console.log(e)
    }
  },
  mounted() {
    this.$store.dispatch('getGetthesingeralbum', { id: this.$route.query.id, limit: this.imit })
  },
  watch: {
    //处理接口返回的时间
    hotAlbums: {
      handler(v, o) {
        this.time = v.map(val => {
          return val.publishTime
        })
        this.title = v.map(val => {
          if (val.alias.length == 0) {
            return ''
          } else {
            return '(' + val.alias[0] + ')'
          }
        })
      }
    },
    time: {
      handler(v, o) {
        this.UTCFullYear = v.map(val => {
          let y = new Date(val)
          return y.getUTCFullYear()
        })
        this.Month = v.map(val => {
          let m = new Date(val)
          return m.getMonth() + 1
        })
        this.UTCDate = v.map(val => {
          let d = new Date(val)
          return d.getUTCDate() + 1
        })
      }
    },
    UTCDate: {
      handler(v, o) {
        for (let i = 0; i < v.length; i++) {
          this.Timemerge.push(this.UTCFullYear[i] + '-' + this.Month[i] + '-' + this.UTCDate[i])
        }
      }
    }
  }
}
</script>

<style lang="less" scoped>
.Arrangementmode {
  margin-top: 20px;
  .main {
    display: flex;
    display: grid;
    grid-template-columns: auto auto auto auto auto auto;
    .imglist {
      margin-bottom: 30px;
      img {
        width: 150px;
        height: 150px;
        border-radius: 5px;
      }
      .p1 {
        font-size: 14px;
        margin-top: 5px;
        width: 150px;
        word-wrap: break-word;
      }
      .p2 {
        font-size: 10px;
        margin-top: 5px;
        opacity: 0.6;
      }
    }
  }
}
</style>